package com.mediocre.mapper;

import com.mediocre.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    @Select("select * from user where name = #{name}")
    List<User> findByName(@Param("name") String name);

    @Insert("insert into user(name, age) values(#{name}, #{age})")
    int insert(@Param("name") String name, @Param("age") Integer age);

    @Insert("insert into user(name, age) values(#{name, jdbcType=VARCHAR}, #{age, jdbcType=INTEGER})")
    int insertByMap(Map<String, Object> map);

    @Insert("insert into user(name, age) values(#{name}, #{age})")
    int insertByUser(User user);

    @Update("update user set age = #{age} where name = #{name}")
    int update(User user);

    @Delete("delete from user where name = #{name}")
    int delete(String name);

    @Results({
        @Result(property = "name", column = "name"),
        @Result(property = "age", column = "age")
    })
    @Select("select name, age from user")
    List<User> findAll();

}
